# Maintainer: Alexander F. Rødseth <xyproto@archlinux.org>
# Contributor: Thomas Weißschuh <thomas@t-8ch.de>

pkgname=smlnj
pkgver=110.99.3
pkgrel=1
pkgdesc='Standard ML compiler from New Jersey'
url='https://www.smlnj.org/'
license=(BSD)
arch=(loong64 x86_64)
makedepends=(smlnj)
provides=(sml)
install=smlnj.install
_url="http://smlnj.cs.uchicago.edu/dist/working/$pkgver/"
source=(
  "$pkgname-$pkgver-boot.amd64-unix.tgz::${_url}boot.amd64-unix.tgz"
  "$pkgname-$pkgver-boot.x64-unix.tgz::${_url}boot.x86-unix.tgz"
  "$pkgname-$pkgver-config.tgz::${_url}config.tgz"
  "$pkgname-$pkgver-cm.tgz::${_url}cm.tgz"
  "$pkgname-$pkgver-compiler.tgz::${_url}compiler.tgz"
  "$pkgname-$pkgver-runtime.tgz::${_url}runtime.tgz"
  "$pkgname-$pkgver-system.tgz::${_url}system.tgz"
  "$pkgname-$pkgver-MLRISC.tgz::${_url}MLRISC.tgz"
  "$pkgname-$pkgver-smlnj-lib.tgz::${_url}smlnj-lib.tgz"
  "$pkgname-$pkgver-ckit.tgz::${_url}ckit.tgz"
  "$pkgname-$pkgver-nlffi.tgz::${_url}nlffi.tgz"
  "$pkgname-$pkgver-cml.tgz::${_url}cml.tgz"
  "$pkgname-$pkgver-ml-lpt.tgz::${_url}ml-lpt.tgz"
  "$pkgname-$pkgver-ml-lex.tgz::${_url}ml-lex.tgz"
  "$pkgname-$pkgver-ml-yacc.tgz::${_url}ml-yacc.tgz"
  "$pkgname-$pkgver-ml-burg.tgz::${_url}ml-burg.tgz"
  "$pkgname-$pkgver-trace-debug-profile.tgz::${_url}trace-debug-profile.tgz"
  urlgetter.sh
  profile.d-smlnj.sh
  smlnj.sh
)
b2sums=('c6a7c96344da723dfd88155586b680b6f54e7711335bc88d8f1468d3f989077febe6624596d16d7236e651f17d33b6bdf268e8a99164b46e21780d87c697551b'
        '52e9f86e7dabaf51ddb642a135f72c6e59f870152107730f7321f7d1d6c165594bdaaf085795360a9dadccec1cd2595c56b7bf7d84d038254273ab8bd5ec1c03'
        '78c6cafc1bc5ac8f6e1fe837c1d1fe8d725eab09713a004a2d89df02c52a2553a2b91a7f540d64b097661b80c1b7bbbbd96f9c2ffdae4e2d3655fd182a7c31aa'
        '6e4ecfc4d74756b1e69a3f61e25649798c6b74327e4d86ff649e9664f22e092a09b80ff0f6e0b94a5210db97985fabc3803e103b3be1da0f9c2bfccb06064e10'
        'c98a337003619d5968f416c83422fb1ed92dbb37423630d41e2600d62a8cda1d2eb02ecd681bc79cb71a51881c1f4e6189430a05726d6345585f87a5585bc66a'
        'ce70bd05fc311ed11285aceb4cb78af7f08a18431538a341f768fc04e9aa3b1df1f0f3f86f384622aea59fb3322eb8446176bf3481df6f0efa5d67fd1bf71da1'
        '9fbb815ee69269ed962899a8374d5669adde670f1846c2137958fb945bc29ac52ae60a1e7393d6fe5479b037641f53bd938555c483683f4f8532c22a44073224'
        'a639a9afcaf1bf3e6521eeaa2dd8cb28f164b4c9b439dcb1370c9189b8ca769fa79f3b6c15aa3ee4db49afd61c321d1a6197ad3a46f7209bd51a431e1249dd49'
        '1904fc25ae19f8a62669e8ad81272702df3871b04a8ee82e3526d5cbec15835d17fb9ebc710fa7cad5634a9485b5ae9534cb9015e96fae4c19d8a51bcb57b77e'
        '0834239040c7e15b96c8ca8812a0d74f5254bbdca22fdba8da5059ec3a256896fa8840dcc18534b9ba3578cb204fe12665f02337f7e1f46af71f19acc2ee4c45'
        '0129c45031c750fcb8b879fa325532170c937ac0dc50e224ff22e1ea7c0822f13794be22ff5bc8c1570ed28b8ff9aa90910cb07b3c18519344bbad17bbf351da'
        '4723c4a9f891274bac82168c21d19ec2506fc01f48fd330b179b468f73174c049df78a3948a10fe245f0f84f2f8b433ed0b64fc0340092e30433b247fbbd3773'
        '3b0a853c92eed28d0d8a4394d1b87761bd093d1e701b289e5de28a351f27e97abb1921a5e5ade6e7dea1faef1dccca4dbcb30aefe4624361b302f14084cf08af'
        '7891b4c26aa44c945f18cd1300fb7c49455c1d2eef4d7ed425509387edd87abea8e23900fa9777798bd7db976d0f4788c3a97120f13c1778b6d476cca190a747'
        '39f9f50f612c5b263f6146d39262d669d7ee3f65daf7d24a0c950ddea8868f13ac6881860f694cba3ecb6b2f29b4755f1364fac2c08401e537d6c355071ebbde'
        '3ef88f8ada0110b91db783901e1efefeea835bef94dbfbbb2de08480adaff79c484abcfb196bc473a0c5d517d6120dad56199c548cf52b5ced712090120afe62'
        '53bc19a0b805bde85527fec711e088e5805420ed969347075f1876ebbc0d13a54a9d5b444da9541fbccdd0e48444ce663806f08ed35095d63d87382dab020f32'
        '6ed6fe0fa9e9dc520e25236dd0002f46eaf243b9a190a61c0f24b3bf20db8127147abd6a84290a81513110b0b7d080e9c4bcb445908f40a8cec67442f4bdbfc1'
        '3666f88b0c79022e52108073a8b6ce96520a31dba27bb3fc101518182244d03ec22eaa8719a7c08c6960ac1c867b885c58f116c04c5da1b7c7aa5e699b0e9b29'
        '619d1d3736750ace9ca4097ec137e10ab3914f905220b54156ea58bb2cf2e0e5cec8ef41e61c03d7c0f0577f4db085c4298ea075dad6c50d206e1d275ff8a981')

build() {
  mkdir -p install
  unset SMLNJ_HOME MAKEFLAGS
  export srcdir
  export pkgver
  export INSTALLDIR="$srcdir/install"
  export CFLAGS="$CFLAGS -Wl,-z,relro,-z-now"
  export LDFLAGS="$LDFLAGS -Wl,-z,relro,-z-now"
  URLGETTER="$srcdir/urlgetter.sh"
  config/install.sh -default 64
}

package() {
  install -d "$pkgdir/usr/"{lib/smlnj,share}
  install -Dm755 "$srcdir/profile.d-smlnj.sh" "$pkgdir/etc/profile.d/smlnj.sh"
  install -Dm644 compiler/LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
  cp -R "$srcdir/install/"{bin,lib} "$pkgdir/usr/lib/smlnj"
  cp -R "$srcdir/doc/man" "$pkgdir/usr/share/"
  find "$pkgdir/usr/share/man" -name '._*' -delete
  install -Dm755 smlnj.sh "$pkgdir/usr/bin/smlnj"
}
